<template>
  <div>
  <el-table
    :data="tableData"
    border
    style="width: 100%"
    :row-class-name="tableRowClassName">
    <el-table-column
      prop="id"
      label="编号"
      width="180">
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="180">
    </el-table-column>
    <el-table-column
      prop="phone"
      label="电话"
      width="180">
    </el-table-column>
    <el-table-column
      prop="email"
      label="邮箱"
      width="180">
    </el-table-column>
    <el-table-column
      prop="address"
      label="地址"
      width="180">
    </el-table-column>
    <el-table-column
      prop="createTime"
      label="创建时间">
    </el-table-column>
  </el-table>
  <!--  分页插件  -->
  <el-pagination
    align="right"
    background
    layout="prev, pager, next"
    :total="totals"
    :current-page="currentPage"
    :page-size="pageSize"
    @current-change="gotoPage">
  </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'emptable',
  data () {
    return {
      tableData: [],
      totals:0,
      currentPage:1,
      pageSize: 5
    }
  },
  methods: {
    gotoPage(curr){
      // 将当前的页码 赋值给data函数中的 currentPage
      this.currentPage = curr;
      // 重新调用一次 获取列表页
      this.getUsers()
    },
    getUsers(){
      // 直接调用接口
      let param = {"currentPage":this.currentPage,"pageSize":this.pageSize}
      this.$http.post('/user/list',param)
        .then(res=>{
          // 将后端返回的数据 赋值给我们data函数中的字段
          this.tableData = res.data.data;
          this.totals = res.data.totals
        })
        .catch(res=>{
          alert("网络不通！")
        })
    },
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
  },
  mounted() {
    this.getUsers();
  }
}
</script>

<style>
.el-table .warning-row {
  background: black;
}

.el-table .success-row {
  background: yellow;
}

